<template>
    <el-select
        v-model="selectedVal"
        :clearable="clearable"
        class="filter-item"
        placeholder="选择渠道方案">
        <el-option label="未选择" :value="0" v-if="form"></el-option>
        <el-option
                v-for="(item, index) in appSourceConfigs"
                :key="index"
                :label="item.id +' ) '+ item.name"
                :value="item.id">
        </el-option>
    </el-select>
</template>

<script>
    export default {
        props: {
            value: {
                type: [String, Number, Array],
            },
            clearable: {
                type: Boolean,
                default: true,
            },
            form: {
                type: Boolean,
                default: false,
            },
        },
        data () {
            return {
                selectedVal: '',
            };
        },
        computed: {
            appSourceConfigs() {
                return this.$store.state.appSourceConfig.all;
            }
        },
        watch: {
            value() {
                this.syncForm();
            },
            selectedVal() {
                this.$emit('input', this.selectedVal);
            }
        },
        methods: {
            getAll() {
                if (!this.appSourceConfigs.length) this.$store.dispatch('appSourceConfig/All', 'appSourceConfig');
            },
            syncForm() {
                this.selectedVal = this.value;
            },
        },
        created() {
            this.getAll();
            this.syncForm();
        }
    }
</script>

<style scoped>

</style>
